// 使用Promise 封装uni.request
// import { emit } from 'process';
import {API_BASE_URL} from '@/config/index.js'
let http = (url,data={},method='get')=>{
	url = API_BASE_URL + url
	return new Promise((reslove,reject)=>{
		uni.request({
		    url, //仅为示例，并非真实接口地址。
		    data,
			method,
		    header: {
		        Authorization : uni.getStorageSync('token') //自定义请求头信息
		    },
		    success: (res) => {
		        // console.log(res.data);
				if(res.data.errCode == 10000){
					reslove(res.data)
				}else{
					uni.showToast({
						title: res.data.errMsg,
						icon:'error'
					})
					reject(res.data.errMsg)
				}
		    },
			fail: (error) => {
				reject(error)
			},
			complete: () => {
				console.log('complete');
			}
		});
	})
}
let get = (url,data={})=>{
	return http(url,data,'get')
}
let post = (url,data={})=>{
	return http(url,data,'post')
}
export default {get,post}